package com.xixun.rainfall;

import android.app.Application;
import android.content.Context;
import android.util.Log;

import com.xixun.rainfall.ui.MainViewModel;

/**
 * @Author： LJH
 * @Time： 2024/6/12
 * @description：
 */
public class App extends Application {
    private static final String TAG = "Rain";
    private MainViewModel mainViewModel;
    private static App app;
    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
    }

    public static App getApp() {
        return app;
    }

    public static void logD(String message){
        Log.d(TAG, message);
    }

    public static void logE(String message){
        Log.e(TAG, message);
    }

    /**
     * 缓存水位
     * @param level
     */
    public void waterLevelSave(String level){
        getSharedPreferences("config", Context.MODE_PRIVATE).edit().putString("waterLevel",level).apply();
    }

    public String waterLevel(){
        return getSharedPreferences("config", Context.MODE_PRIVATE).getString("waterLevel","1.23m");
    }

    public void hourlyRainfallSave(String level){
        getSharedPreferences("config", Context.MODE_PRIVATE).edit().putString("hourlyRainfall",level).apply();
    }

    public String hourlyRainfall(){
        return getSharedPreferences("config", Context.MODE_PRIVATE).getString("hourlyRainfall","13.4mm");
    }

    public void dailyRainfallSave(String level){
        getSharedPreferences("config", Context.MODE_PRIVATE).edit().putString("dailyRainfall",level).apply();
    }

    public String dailyRainfall(){
        return getSharedPreferences("config", Context.MODE_PRIVATE).getString("dailyRainfall","13.4mm");
    }

    public MainViewModel getMainViewModel() {
        return mainViewModel;
    }

    public void setMainViewModel(MainViewModel mainViewModel) {
        this.mainViewModel = mainViewModel;
    }
}
